package com.demo.gateway.quartz;

import java.lang.reflect.Method;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.demo.gateway.pojo.ScheduleJobDO;
import com.demo.gateway.util.SpringContextUtil;


/**
 * @author: demo
 * @date: 2020年6月28日
 * @Document : 定时器工厂
 */
public class ScheduleJobFactory implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        ScheduleJobDO scheduleJob = (ScheduleJobDO) jobExecutionContext.getMergedJobDataMap().get("scheduleJob");

        //获取定时Bean
        Object object =SpringContextUtil.getBean(scheduleJob.getBeanName());
        try {
            Method method = object.getClass().getMethod(scheduleJob.getMethodName());
            method.invoke(object);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
